package com.qf.controller;

import com.qf.dto.TProductSearchDTO;
import com.qf.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author LiuLiang
 * @Date 2020/3/16
 */
@Controller
//@RequestMapping("/web/search")
public class SearchController {
    @Autowired
    private SearchService searchService;

    @RequestMapping("/initData")
    @ResponseBody
    public String initData(){
        searchService.initDataToSolr();
        return "success";
    }

    @RequestMapping("/search")
    public String searchGoodsByKeywords(String keywords, Integer pageNum,Integer pagesize, Model model){
        System.out.println(keywords+"-----"+pageNum+"------"+pagesize);
        List<TProductSearchDTO> productList = searchService.searchGoodsByKeywords(keywords,pageNum,pagesize);
        model.addAttribute("productList",productList);
        model.addAttribute("keywords",keywords);
        model.addAttribute("pageNum",pageNum);
        return "search";
    }

}
